<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script type="text/javascript">
			/**
			 * 除数不能为0 infinity
			 * 2.输入值必须是数字
			 * 3.加法乘法精度问题
			 * 4.
			 */
			function sub(){
				let input1= document.getElementById("input1").value;
				let input2=document.getElementById("input2").value;
				
				let r=input1-input2;
				document.getElementById("n3").value=r;
			}
			function sum(){
				let input1= document.getElementById("input1").value;
				let input2=document.getElementById("input2").value;
				let r=Number(input1)+Number(input2);
				r=r.toFixed(15);//精确到15位,解决精度问题
				r=r-0;//可以把后面的0省略掉
				document.getElementById("n3").value=r;
			}
			
			function mul(){
				let input1= document.getElementById("input1").value;
				let input2=document.getElementById("input2").value;
				let r=Number(input1)*Number(input2);
				r=r.toFixed(15);
				document.getElementById("n3").value=r;
			}
			function div(){
				let input1= document.getElementById("input1").value-0;
				let input2=document.getElementById("input2").value-0;
				if(isNan(Number(input1))||isNaN(Number(input2))){
					document.getElementById("n3").value="只能运算数字";
					return;
				}
				if(input2===0){
					document.getElementById("n3").value="除数不能为0";
					return;
				}
				let r=Number(input1)/Number(input2);
				r=r.toFixed(15);
				document.getElementById("n3").value=r;
			}
			
		</script>
	</head>
	<body>
		第一个数:<input id=input1 type="text"/>
		<br>
		第二个数:<input id=input2 type="text"/>
		<br>
		<button onclick="sum()">+</button>
		<button onclick="sub()">-</button>
		<button onclick="mul()">*</button>
		<button onclick="div()">/</button>
		<br>
		计算结果: <input id=n3 type="text"/ disabled="disabled">
	</body>
</html>
